package com.jy.appmarket.adapter;

import com.jy.appmarket.R;
import com.jy.appmarket.utils.GalleryImageLoader;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class GalleryAdapter extends SimpleBaseAdapter<String>{

	private String mDirPath;

	public GalleryAdapter(Context context, String dirPath) {
		super(context);
		mDirPath = dirPath;
	}

	public void setDirPath(String dirPath) {
		mDirPath = dirPath;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String imageName = mList.get(position);
		ViewHolder holder;
		if (convertView == null) {
			convertView = getInflater().inflate(R.layout.item_gallery_gridview, parent, false);
			holder = new ViewHolder();
			holder.image = convertView.findViewById(R.id.item_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		if (position == 0) {
			holder.image.setScaleType(ImageView.ScaleType.CENTER);
			holder.image.setImageResource(R.drawable.icon_take_picture);
		} else {
			holder.image.setScaleType(ImageView.ScaleType.CENTER_CROP);
			holder.image.setImageResource(R.drawable.banner_loading_icon);
			GalleryImageLoader.getInstance(3, GalleryImageLoader.Type.LIFO).loadImage(mDirPath + "/" + imageName, holder.image);
		}
		
		//ImageLoader.getInstance().displayImage("file://" + mDirPath + "/" + imageName, holder.image);
		return convertView;
	}

	private static class ViewHolder {
		private ImageView image;
	}
}
